<template>
  <div>
    <el-card style="margin-top: 10px;">

      <el-breadcrumb separator-class="el-icon-arrow-right">
      <!-- <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item> -->
      <div class="manager-all">
          <div class="project-manager"></div>
          <div class="project-item">
            <el-breadcrumb-item :to="{ path: '/' }"
            >权限管理
            </el-breadcrumb-item
            >
          </div>
        </div>
    </el-breadcrumb>

      <el-row :gutter="5" style="float: right;">
        <!--        <el-col :span="12" class="row-flex">-->
        <!--          <el-button type="primary" @click="showEditDialog" class="add"-->
        <!--          ><img src="../../icon标/修改.png" class="addimg" alt="">-->
        <!--            修改-->
        <!--          </el-button>-->
        <!--        </el-col>-->
        <el-col :span="12" class="row-flex">
          <el-button type="primary" @click="goToLink" class="add3"
          >返回列表
          </el-button>
        </el-col>
      </el-row>

      <hr
        style="width: 1642px;
                height: 1px;
                border:none;
                background: #E8ECF0;
                margin-left:-23px;"
      />
      <div style="margin-top: 30px;margin-left: 50px;">用户名：
        <el-input type="text" v-model="userName" readonly=""
                  style="width: 200px;"></el-input></div>
      <!--      //需要 用户名 和他在的所有组-->
      <!--      展示形式为列表有点难看吧-->
      <el-table
        :data="powerList"
        style="width:90%;margin-left: 50px;margin-top:20px;"
        class="bioTable"
        :header-cell-style="{ background: '#F6F7FB' }">
        <el-table-column label="组名" prop="groupName"></el-table-column>
        <el-table-column
          label="权限"
          prop="permission">
          <template slot-scope="scope">
<!--            <el-switch-->
<!--              style="display: block"-->
<!--              active-color="#13ce66"-->
<!--              inactive-color="#ff4949"-->
<!--              active-text="只读"-->
<!--              inactive-text="读写"-->
<!--              v-model="scope.row.permission"-->
<!--              :active-value="1"-->
<!--              :inactive-value="0"-->
<!--              @change="changePower(scope.row)">-->
<!--            </el-switch>-->
            <el-select v-model="scope.row.permission" placeholder="请选择" @change="changePower(scope.row)">
              <el-option label="只读" :value="1"></el-option>
              <el-option label="读写" :value="0"></el-option>
              <el-option label="无权限" :value="-1"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          label="管理"
          prop="level">
          <template slot-scope="scope">
            <div class="btn-all">
              <div class="bj">
                <i class="el-icon-edit-outline" style="color:#409EFF;"></i>
                <!--              整个Button-->

                <router-link
                  type="success"
                  :underline="false"
                  style="margin-left:5px;font-size:14px;cursor: pointer;text-decoration: none;color: rgb(64, 158, 255) !important;"
                  :to="{path:'/groupMember/'+scope.row.groupId,query:{Upage:Upage,Usize:Usize,Uid:query.id}}"
                >成员信息
                </router-link>
              </div>
              <div class="sx"></div>
              <div class="sc">
                <i class="el-icon-delete" style="color:#F56C6C;"></i>
                <el-link
                  type="danger"
                  :underline="false"
                  @click="removeUserInGroup(scope.row)"
                  style="margin-left:5px;font-size:14px;cursor: pointer;"
                >请出该组
                </el-link>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "powerManaged",
  data() {
    return {
      userName:'',
      powerList: [],
      query: {
        id: 0
      },
      Upage:'',
      Usize:''
    }
  },
  created() {

    var query=this.$route.query
    if(query.Upage!=null){
      this.Upage=Number(query.Upage)
    }
    if(query.Usize!=null){
      this.Usize=Number(query.Usize)
    }
    this.query.id = this.$route.params.id;
    console.log(this.$route.params.id)
    this.selectUserName()
    this.getPowerList()


  },
  methods: {
    async selectUserName() {
      // const {data: res} = await this.$axios.post(`group/list?page=${this.queryInfo.page}&size=${this.queryInfo.size}&query=${this.queryInfo.query}`);
      const {data: res} = await this.$axios.get("userManager/getUserInfo", {
        params: {
          id:this.$route.params.id
        }
      });
      if (res.code !== 200) {
        return this.$message.error("获取角色信息失败！");
      }
      // console.log(res.用户信息.username)
      this.userName=res.用户信息.username
    },
    // 这个不搞分页
    async getPowerList() {
      const {data: res} = await this.$axios.get("group/getUserGroup", {
        params: this.query
      });
      if (res.code !== 200) {
        return this.$message.error("获取角色列表失败！");
      }
      console.log(res)
      this.powerList = res.data;
      this.total = res.total;
      console.log('now')
      console.log(this.powerList);

    },
    goToLink() {
      //指定跳转地址
      //指定跳转地址
      this.$router.push({path:'/userManaged',query:{Upage:this.$route.query.Upage,Usize:this.$route.query.Usize}})
      // this.$router.replace('/userManaged')
    },
    async removeUserInGroup() {
      // 弹框询问用户是否删除数据
      const confirmResult = await this.$confirm(
        "此操作该用户将退出本小组, 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
          // 如果取消 会抛出一个错误error 这里用catch捕获他 然后返回error
          // 可以简写成.catch(err => err)
        }
      ).catch(error => {
        return error;
      });
      // 如果用户确认删除，返回值为字符串 confirm
      // 如果用户取消删除，返回值为字符串 cancel
      if (confirmResult !== "confirm") {
        return this.$message.info("以取消删除");
      }
      // console.log('已删除用户')
      const {data: res} = await this.$axios.delete("userManager/deleteUser?id=" + id);
      console.log(res);
      if (res.code !== 200) {
        return this.$message.error("退出失败！");
      }
      this.$message.success("退出成功!");
      await this.getPowerList();

    },
    async changePower(row) {
      const {data: res} = await this.$axios.post("group/setGroupAuth",row);
      if (res.code !== 200) {
        return this.$message.error("获取角色列表失败！");
      }
      console.log(res)
      this.powerList = res.data;
      console.log('now')
      await this.getPowerList()


    }
  }
}
</script>
<style>
.bioTable {
  margin-top: 20px;
}

.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  /*width: 90px;*/
  color: #99a9bf;
}

.demo-table-expand {
  margin-right: 0;
  margin-bottom: 0;
}

.expand-msg {
  border-radius: 1px !important;
  border: 1px solid rgba(239, 239, 239, 0.36);
  /*height: 50px;*/
  line-height: 50px;
  /*border: 1px solid #000 !important;*/
  /*border-right: none;*/
}

.expand-msg-left {
  border-left: 2px solid rgba(239, 239, 239, 0.36);
  /*border-left: 2px solid #d7dae2;*/
}

.table-item {
  margin-bottom: 0px !important;
  line-height: 50px;
  padding-left: 10px;
}

.table-item-span {
  line-height: 50px;
}

.add-button {
  margin-top: 5px;
}

.table-image {
  width: auto;
  height: auto;
  /*max-width: 50%;*/
  /*max-height: 50%;*/
  display: block;
}

/*.el-form-item .table-item label{*/
/*  line-height: 50px;*/
/*  border-left: 2px solid #d7dae2;*/
/*  padding-left: 10px;*/
/*}*/
/*.el-form-item .demo-table-expand{*/
/*  margin-bottom: 0px !important;*/
/*}*/

/*.el-form-item__content{*/
/*  line-height: 50px;*/
/*  border-left: 2px solid #d7dae2;*/
/*  padding-left: 10px;*/
/*}*/
/*.el-form-item__label{*/
/*  padding-left: 10px;*/
/*}*/
.btn-all {
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.cell {
  text-align: center;
}

.sx {
  width: 1.5px;
  height: 18px;
  /* font-size: 14px;
  font-weight: 400; */
  background: #ccccccff;
}

.addimg {
  width: 22px;
  height: 16px;
  margin-left: 0px;
  margin-top: 0;
  float: left;
}
.manager-all {
  margin-top: 6px;
  display: flex;
  height: 30px;
  width: 100px;
  justify-content: center;
  margin-bottom: 30px;
  float: left;
}

.project-manager {
  width: 4px;
  height: 30px;
  background: #4087fc;
}

.project-item {
  width: 72px;
  height: 18px;
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 600px;
  color: #333333;
  margin-left: 10px;
  line-height: 30px;
}
.add3 {
  width: 160px !important;
  height: 36px;
  background: #4087fc;
  border-radius: 6px;
  float: left;
  margin-top: -60px;
}
/* a {
  text-decoration: none;
  color: #67c23a;
} */

.Biosearch {
  margin-top: 25px;
  background: rgba(247, 247, 247, 1);
  display: flex;
  height: 100px;
  align-items: center;
  padding: 0 30px;
  justify-content: space-between;
}
</style>
<style>

</style>
